package net.yxsoft.kit;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.PropKit;
import net.yxsoft.resource.Res;

import java.util.HashMap;
import java.util.Map;

public class MobileKit {
    public static Map<String,String>  getMobile(String openId,String accessToken){
        String mobileurl = PropKit.get("ysf.mobileurl");
        String backendToken = BackendTokenKit.getBackendToken();
        String appid = PropKit.get("ysf.appId");

        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("appId", appid);
        paramMap.put("accessToken", accessToken);
        paramMap.put("openId", openId);
        paramMap.put("backendToken", backendToken);

        String jsonStr = HttpKit.post(mobileurl, JsonKit.toJson(paramMap));
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        Map<String,String> map= new HashMap<String,String>();
        System.out.println(jsonObject);
        if(jsonObject.getString("resp").equals("00")) {
            JSONObject jsonObjectparames = JSONObject.parseObject(jsonObject.getString("params"));
            try {
                map.put("mobile", Ysf3DESKit.getDecryptedValue(jsonObjectparames.getString("mobile"),PropKit.get("ysf.symmetricKey")));
            } catch (Exception e) {
                e.printStackTrace();
                map.put("mobile","");
            }
            map.put("cntryPhoneCd", jsonObjectparames.getString("cntryPhoneCd"));
        }
        return map;

    }
}
